import {defineStore} from 'pinia'

/**
 * 本地配置
 */
export const useConfigStore = defineStore('configStore', {
    //第三方插件的持久化配置
    persist: {
        enabled: true,
        strategies: [{
            storage: localStorage
        }]
    },
    state: () => {
        return {
            env: import.meta.env.VITE_PROJECT_ENV,
            serverHost: import.meta.env.VITE_BASE_API_URL,
            websocketUrl: import.meta.env.VITE_WEBSOCKET_URL,
            signalHost: import.meta.env.VITE_SIGNAL_HOST,
            signalPort: import.meta.env.VITE_SIGNAL_PORT,

            isNight: window.matchMedia("(perfers-color-scheme: dark)").matches,
            language: 'zh',
        }
    },
    actions: {
        swapNight() {
            this.isNight = !this.isNight
        },

        setLanguage(code) {
            this.language = code
        }
    }
})
